<template>
  <div class="signin-container">
    <el-card>
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.username"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input type="password" v-model="form.password"></el-input>
        </el-form-item>
        
        <el-form-item>
          <el-button type="primary" @click="onSubmit">登录</el-button>
          <el-input class="reset" type="reset">重置</el-input>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
export default {
  data() {
    return {
      form: {
        username: 'admin',
        password: '123'
      }
    }
  },
  methods: {
    async onSubmit() {
      let result = await this.$http.post({
        url: '/users/signin',
        data: JSON.stringify(this.form)
      })
      let token = result['headers']['x-access-token']
      localStorage.setItem('x-access-token', token)

      this.$router.push('/')
    }
  }
}
</script>

<style lang='stylus' scoped>
.signin-container
  height 100%
  display flex
  justify-content center
  align-items center
  .el-form
    width 400px
    .reset
      width auto
      margin-left 10px
</style>